/**
 * Copyright 2014 Kakao Corp.
 *
 * Redistribution and modification in source or binary forms are not permitted without specific prior written permission. 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kakao.sample.usermgmt;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import com.kakao.UpdateProfileResponseCallback;
import com.kakao.UserManagement;

import android.content.Context;
import android.os.UserManager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewDebug.IntToString;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.Spinner;
import android.widget.TextView;

/**
 * 추가로 받고자 하는 사용자 정보를 나타내는 layout
 * 이름, 나이, 성별을 입력할 수 있다.
 * @author MJ
 */
public class ExtraUserPropertyLayout extends FrameLayout {
    // property key
    private  static String RECORD_KEY = "record";
    private  static String WIN_KEY = "win";
  
    private TextView record;
    private TextView win;
   
    
    public int start = 1;
    public int winner = 1;
    public boolean win1 = false;
    public static boolean gamestart = false;
  
    public ExtraUserPropertyLayout(Context context) {
        super(context);
    }

    public ExtraUserPropertyLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public ExtraUserPropertyLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onAttachedToWindow () {
        super.onAttachedToWindow();
        final View view = inflate(getContext(), R.layout.extra_user_property, this);
        record = (TextView) view.findViewById(R.id.record);
        win = (TextView) view.findViewById(R.id.win);
//        gender = (Spinner) view.findViewById(R.id.gender);
    }
//    record.getText().toString()
    Map<String, String> getProperties(){
    	
    		if(gamestart == true)
    	{
//    	    for(int i=0; i<2; i++)
    		 gamestart = false;
    		 Log.d("tag", Integer.toString(UsermgmtMainActivity.sum));
        String recordValue = (Integer.toString(UsermgmtMainActivity.sum));
        String winValue = null;
        if(win1 == false){
        winValue = win.getText().toString() + Integer.toString(winner);
//        final String genderValue = String.valueOf(gender.getSelectedItem());
        }
    	
        else if(win1 == true){
        winValue = win.getText().toString();
        };
        Map<String, String> properties = new HashMap<String, String>();
        if(recordValue != null)
            properties.put(RECORD_KEY, recordValue);
        	
        if(winValue != null)
            properties.put(WIN_KEY, winValue);
//        if(genderValue != null)
//            properties.put(GENDER_KEY, genderValue);
       
        return properties;
    	}
			return null;
    	    	}

    		

    void showProperties(final Map<String, String> properties) {
        final String recordValue = properties.get(RECORD_KEY);
        if (recordValue != null)
            record.setText(recordValue);

        final String winValue = properties.get(WIN_KEY);
        if (winValue != null)
            win.setText(winValue);

//        final String genderValue = properties.get(GENDER_KEY);
//        if (genderValue != null) {
//            ArrayAdapter<String> myAdap = (ArrayAdapter<String>) gender.getAdapter(); //cast to an ArrayAdapter
//            int spinnerPosition = myAdap.getPosition(genderValue);
//            gender.setSelection(spinnerPosition);
//        }
    }


}
